<?php

namespace App\Http\Resources\Dashboard;

use Illuminate\Http\Resources\Json\JsonResource;

class UserWorkResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {

        switch ($this->work->type) {
            case 2:
                $result = json_decode($this->result, true);
                break;
            case 3:
                $result = url('/storage/attachment/work/' . $this->result);
                break;
            case 1:
            default:
                $result = $this->result;
        }
        return ['user_id' => $this->user->id, 'user_name' => $this->user->name, 'work_id' => $this->work->id, 'question' => $this->work->question, 'result' => $result, 'mark' => $this->review['mark'] ?? null, 'type' => $this->work->type, 'created_at' => $this->created_at];
    }
}
